package com.lagou.filter;

import com.lagou.common.Common;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @author banzijian
 * @date 2020/10/23
 **/
@Activate(group = {CommonConstants.CONSUMER})
public class TransportIPFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String ip = Common.IP_THREAD_LOCAL.get();
        System.out.println("Filter 向 RpcContext 中设置ip, ip: " + ip);
        RpcContext.getContext().setAttachment(Common.REQUEST_IP, ip);
        // 执行方法
        return  invoker.invoke(invocation);
    }
}
